<?php
/**
 * Created by PhpStorm.
 * User: baidu
 * Date: 17/8/6
 * Time: 上午2:45
 */
namespace app\common\library\exception;
use think\exception\Handle;

class ApiHandleException extends  Handle {

    /**
     * http 状态码
     * @var int
     */
    public $httpCode = 500;
    public $code = 0;

    public function render(\Exception $e) {
        if(config('app_debug') == true) {
            return parent::render($e);
        }
        if ($e instanceof ApiException) {
            $this->httpCode = $e->httpCode;
            $this->code = $e->code;
        }
        if (preg_match("/.*Request AccessToken fail.*/i", $e->getMessage())) {
            return show($this->code, '当前小程序正在维护中', [], $this->httpCode);
        }else{
            return  show($this->code, $e->getMessage(), [], $this->httpCode);
        }
    }
}